// components/chatPanel/index.js

const app = getApp()

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    chatInfoList:Array,
    chatKey:String,
    duration:Number,
    isBlurState:{
      type:Boolean,
      value:true
    }
  },

  ready() {
   if(this.data.chatInfoList&&this.data.chatInfoList.length){
    console.log('chatKey=========',this.data.chatKey)
     this.data.chatInfoList.forEach(item => {
       if(item.type == 'voice'){
        this.triggerEvent('playVoice',{
          id:this.data.chatKey,
          url:item.voice_data.base64_voice_data
        })
       }
     });

   }
  },

  /**
   * 组件的初始数据
   */
  data: {
    panelClass:'chat-panel',
    imgUrl:'',
    imgShow:false,
    userAvatarUrl:app.globalData.userInfo.avatarUrl||"../../assets/my-avatar.png",
    waveInfo:{
      num:36,
      backgroundColor:"#4E6CEE",
      width: '4rpx',
      height: '5rpx',
      marginRight: '5rpx',
    },
    activeSelect:''
  },
  lifetimes:{
    attached(){
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
      toAds(e){
        const { value } = e.currentTarget.dataset
        this.setData({
          activeSelect:value
        })
        console.log('activeSelect===========',this.data.activeSelect)
        this.triggerEvent('toAds',value)
      },
      playVoice(e){
        const { url } = e.currentTarget.dataset
        this.triggerEvent('playVoice',{
          id:this.data.chatKey,
          url:url,
          isClick:true
        })
      },
      onPhraseClick: function (e) {
        console.log('target=========',e)
        if(e.currentTarget.dataset.phrase){
          this.triggerEvent('showPopCard',e.currentTarget.dataset.phrase)
        }
      },
      onTapImg(e){
        const {url} = e.currentTarget.dataset
        this.setData({
          imgUrl:url,
          imgShow:true
        })
      },
      closeImg(){
        this.setData({
          imgShow:false
        })
      }
  }
})